<div class="main_content">	
	
	<% if !@entities.nil? %>
		<h2>Search Results</h2>
		<div class="table_div">
			<% @entities.each do |entity| %>
				<% unless session[:user_id] == entity.id%>
					<div class="table_row_div">
					
						<div class="table_cell_div_action">
							<% if User.exists?(entity.id)  %>
								<% current_user = Entity.find(session[:user_id]) %>
								<% if current_user.has_friend_requested(entity.id) %>
									<%= link_to 'Remove friend request sent to ' + entity.name , remove_friend_request_path(entity.id) %>
								<% elsif current_user.friend_request_received(entity.id) %>
									<%= link_to 'Accept friend request from ' + entity.name, accept_friend_request_path(Friendship.find_by_entity_id_and_friend_id(entity.id, session[:user_id]).id), :confirm => 'Are you sure?' %>				
								<% elsif !current_user.is_friends_with(entity.id) %>
									<% if entity.can_be_sent_friend_request(current_user) %>
										<%= link_to 'Add ' + entity.name + ' as a friend', add_friend_path(entity.id) %>
									<% else %>
										<p><%= entity.name %> does not allow friend requests</p>
									<% end %>				
								<% else %>
									<%= entity.name + " is your friend" %>
								<% end %>
							<% else %>
								<% if Entity.find(session[:user_id]).is_friends_with(entity.id) %>
									<%= "You are part of group " + entity.name %>
								<% else %>
									<%= link_to 'Join group ' + entity.name, add_friend_path(entity.id) %>
								<% end %>
							<% end %>
						</div>
						<div class="table_cell_div_view">
							<%= link_to "View " + entity.name + " (" + entity.type + ")", show_friend_path(entity) %>
						</div>
						
					</div>
				<% end %>
			<% end %>
		</div>
	<% end %>
	
	<h2> Search </h2>	
	<div id="search_query_container">
		<% form_tag entities_path, :method => 'get' do %>
			<div class="search_radios">
				<label for="type_all"><input id="type_all" name="type" type="radio" value="All", checked="checked" />All</label>
				<label for="type_user"><input id="type_user" name="type" type="radio" value="User" /> Users</label>
				<label for="type_group"><input id="type_group" name="type" type="radio" value="Group" /> Groups</label>				
			</div>
			<div class="search_input">
				<label for="search">Type search terms here: </label>
				<%= text_field_tag :search %>
				<input class="submit_search" type="submit" title="Click here to begin the search" value="Search"/>				
			</div>	
			<div id="wrapper"></div>
		<% end %>
		<div id="wrapper"></div>
	</div>
	<div id="wrapper"></div>
	<p style="float:left;clear:left"><%= @search_filter %></p>		<!-- MAKE THIS APPEAR AS AN ALERT -->
	
</div>
